<!-- src/views/message.vue -->
<script setup lang="ts">
import { ref } from 'vue'

// 模拟评论数据
const comments = ref([
  {
    id: 1,
    avatar: 'https://img01.yzcdn.cn/vant/cat.jpeg',
    nickname: 'L.N',
    text: '一看就像预制菜',
    time: '03-26',
    location: '江西',
    likes: 3,
    replies: [
      {
        id: 11,
        avatar: 'https://img01.yzcdn.cn/vant/user.png',
        nickname: '吃吃喝喝',
        role: '作者',
        text: '还真不是😂',
        time: '03-26',
        location: '江西'
      }
    ]
  },
  {
    id: 2,
    avatar: 'https://img01.yzcdn.cn/vant/boy.jpeg',
    nickname: 'MR.13',
    badge: '社区金句侠',
    text: '已经带了几任了？😎',
    time: '08-11',
    location: '江西',
    likes: 1,
    replies: []
  },
  {
    id: 3,
    avatar: 'https://img01.yzcdn.cn/vant/girl.jpeg',
    nickname: '卡哇伊',
    text: '环境也很好哦',
    time: '03-23',
    location: '',
    likes: 2,
    replies: []
  },
  {
    id: 4,
    avatar: 'https://img01.yzcdn.cn/vant/pet.jpeg',
    nickname: '于梦见君',
    text: '有无辣的选择？不太能吃辣诶',
    time: '08-10',
    location: '江西',
    likes: 1,
    replies: []
  },
  {
    id: 5,
    avatar: 'https://img01.yzcdn.cn/vant/man.jpeg',
    nickname: 'sunny',
    text: '现炒菜美味',
    time: '03-21',
    location: '江西',
    likes: 0,
    replies: []
  }
])

// 输入框
const inputText = ref('')
const currentCommentId = ref(null)

// 点赞
const like = (id: number) => {
  const comment = comments.value.find(c => c.id === id)
  if (comment) {
    comment.likes++
  }
}

// 发布评论
const submitComment = () => {
  if (!inputText.value.trim()) return
  // 这里可以添加发布逻辑
  console.log('提交评论:', inputText.value)
  inputText.value = ''
}
</script>

<template>
  <div class="message-page">
    <div class="header">
      <h1>吃吃喝喝</h1>
      <div class="actions">
        <van-button type="primary" size="small">关注</van-button>
        <van-icon name="share" size="20" />
      </div>
    </div>

    <div class="comments-section">
      <h3>7 条评论</h3>

      <!-- 评论输入框 -->
      <div class="input-area">
        <van-image round width="40" height="40" src="https://img01.yzcdn.cn/vant/cat.jpeg" />
        <van-field
            v-model="inputText"
            placeholder="真实发声，言之有物"
            right-icon="smile-o"
            clearable
            @click-right-icon="() => {}"
        />
      </div>

      <!-- 评论列表 -->
      <div class="comments-list">
        <div v-for="comment in comments" :key="comment.id" class="comment-item">
          <div class="comment-header">
            <van-image round width="40" height="40" :src="comment.avatar" />
            <div class="user-info">
              <div class="nickname">{{ comment.nickname }}</div>
              <div v-if="comment.badge" class="badge">{{ comment.badge }}</div>
            </div>
          </div>
          <div class="comment-body">
            <p>{{ comment.text }}</p>
            <div class="meta">
              <span>{{ comment.time }}</span>
              <span v-if="comment.location"> {{ comment.location }}</span>
              <span>回复</span>
            </div>
          </div>
          <div class="comment-actions">
            <van-button size="mini" @click="like(comment.id)">
              <van-icon name="like-o" /> {{ comment.likes }}
            </van-button>
            <van-button size="mini" @click="currentCommentId = comment.id">
              回复
            </van-button>
          </div>

          <!-- 回复列表 -->
          <div v-if="comment.replies && comment.replies.length > 0" class="replies">
            <div v-for="reply in comment.replies" :key="reply.id" class="reply-item">
              <div class="reply-header">
                <van-image round width="30" height="30" :src="reply.avatar" />
                <div class="reply-user">
                  <span class="nickname">{{ reply.nickname }}</span>
                  <span v-if="reply.role" class="role">{{ reply.role }}</span>
                </div>
              </div>
              <div class="reply-body">
                <p>{{ reply.text }}</p>
                <div class="meta">
                  <span>{{ reply.time }}</span>
                  <span v-if="reply.location"> {{ reply.location }}</span>
                  <span>回复</span>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 底部操作栏 -->
    <div class="bottom-bar">
      <van-field v-model="inputText" placeholder="真实发声，言之有物" />
      <div class="actions">
        <van-icon name="like-o" size="20" />
        <span>147</span>
        <van-icon name="star-o" size="20" />
        <span>72</span>
        <van-icon name="chat-o" size="20" />
        <span>7</span>
      </div>
    </div>
  </div>
</template>

<style scoped>
.message-page {
  padding: 10px;
  background: #f8f8f8;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid #eee;
}

.comments-section {
  margin-top: 20px;
}

.input-area {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
  background: white;
  border-radius: 20px;
  padding: 5px 10px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.comments-list {
  background: white;
  border-radius: 8px;
  padding: 10px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.comment-item {
  margin-bottom: 15px;
  padding: 10px;
  border-bottom: 1px solid #eee;
}

.comment-header {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
}

.user-info {
  margin-left: 10px;
}

.nickname {
  font-weight: bold;
  font-size: 14px;
}

.badge {
  font-size: 10px;
  color: #ff9900;
  background: #fff9e6;
  padding: 2px 6px;
  border-radius: 4px;
}

.comment-body p {
  margin: 0;
  line-height: 1.5;
}

.meta {
  font-size: 12px;
  color: #999;
  margin-top: 4px;
}

.comment-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.replies {
  margin-top: 10px;
  padding-left: 40px;
  border-left: 1px dashed #eee;
}

.reply-item {
  margin-bottom: 8px;
}

.reply-header {
  display: flex;
  align-items: center;
  margin-bottom: 4px;
}

.reply-user {
  margin-left: 8px;
}

.reply-body {
  font-size: 14px;
  color: #666;
}

.bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: white;
  padding: 10px;
  box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.actions {
  display: flex;
  gap: 15px;
  font-size: 14px;
  color: #999;
}
</style>
